Skip to content

feat: enrich transaction history with known transaction data#216

Merged
premiumjibles merged 3 commits intomainfrom
feat/tx-history-enrichment
Mar 17, 2026
Merged

feat: enrich transaction history with known transaction data#216
premiumjibles merged 3 commits intomainfrom
feat/tx-history-enrichment

Conversation

@premiumjibles
Copy link
Contributor

@premiumjibles premiumjibles commented Mar 14, 2026

Summary

  • Transaction history enrichment pipeline: Reclassifies generic "Contract interaction" transactions into their actual types (swap, send, limit order, stop-loss, TWAP, deposit, withdraw, approval) using known transaction metadata from tool executions
  • Expanded type system: Adds 6 new transaction types (limitOrder, stopLoss, twap, deposit, withdraw, approval) across the types package, server enrichment, and chat UI
  • Extracted getKnownTransactions() selector: Moves inline knownTransactions builder from ChatProvider.tsx into chatStore.ts, covering all 9 transaction-producing tools (swap, swapUsd, send, limitOrder, stopLoss, twap, vaultDeposit, vaultWithdraw, vaultWithdrawAll) with proper sub-transaction handling (approval/deposit sub-txs)
  • UI updates: New icons (ScrollText for orders, Vault for deposits/withdrawals, ShieldCheck for approvals), label map, and grouped render logic (isSwapLike, isSendLike, isReceiveLike, isContractLike)
  • LLM compliance: Schema and prompt improvements for the transaction history tool

Test plan

  • bun run lint — passes
  • bun run type-check — passes (discriminated union expanded across all consumers)
  • bun test — 828 tests, 0 failures (15 enrichment tests including 8 new ones for new types)
  • Manual: trigger swap → tx history shows "Swap" with swap pair UI
  • Manual: create limit order → tx history shows "Approval" + "Limit Order"
  • Manual: vault deposit → tx history shows "Deposit" with correct icon
  • Manual: vault withdraw → tx history shows "Withdraw" with correct icon

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Extended transaction history support to include limit orders, stop losses, TWAP orders, deposits, withdrawals, and approvals.
    • Enhanced AI chat context with known transaction data for improved responses.
  • Bug Fixes

    • Improved transaction type classification and enrichment to accurately identify swap-related and other transaction types.
    • Fixed transaction display logic for improved accuracy across multiple transaction flows.
  • Refactor

    • Optimized transaction history storage and retrieval mechanisms.

@vercel
Copy link

vercel bot commented Mar 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
shapeshift-agentic Ready Ready Preview, Comment Mar 17, 2026 8:26am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 01391fce-c41c-4135-b24c-b35a7d2bbf25

📥 Commits

Reviewing files that changed from the base of the PR and between 077b95f and fb57255.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • .tickets/sa-hhve.md
  • .tickets/sa-qczu.md
  • apps/agentic-chat/package.json
  • apps/agentic-chat/src/components/tools/GetTransactionHistoryUI.tsx
  • apps/agentic-chat/src/lib/transactionUtils.ts
  • apps/agentic-chat/src/providers/ChatProvider.tsx
  • apps/agentic-chat/src/stores/chatStore.ts
  • apps/agentic-server/src/lib/transactionHistory/__tests__/enrichment.test.ts
  • apps/agentic-server/src/lib/transactionHistory/__tests__/evmParser.test.ts
  • apps/agentic-server/src/lib/transactionHistory/__tests__/query.test.ts
  • apps/agentic-server/src/lib/transactionHistory/enrichment.ts
  • apps/agentic-server/src/lib/transactionHistory/evmParser.ts
  • apps/agentic-server/src/lib/transactionHistory/query/sort.ts
  • apps/agentic-server/src/lib/transactionHistory/schemas.ts
  • apps/agentic-server/src/routes/chat.ts
  • apps/agentic-server/src/tools/transactionHistory.ts
  • apps/agentic-server/src/utils/walletContextSimple.ts
  • packages/types/src/tx.ts

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

This PR introduces transaction enrichment capabilities by adding support for new transaction types (limitOrder, stopLoss, twap, deposit, withdraw, approval), implementing client-side persistence of known transactions via IndexedDB, and establishing a server-side enrichment pipeline that maps known transactions to on-chain data while accounting for internal native ETH transfers.

Changes

Cohort / File(s) Summary
Documentation & Investigation
.tickets/sa-hhve.md, .tickets/sa-qczu.md
Two new ticket files documenting cross-chain Safe address mismatch bug analysis and token approval timing investigation with root cause analysis and proposed solutions.
Type System Extensions
packages/types/src/tx.ts
Extended TRANSACTION_TYPES constant and ParsedTransaction union to include six new transaction types: limitOrder, stopLoss, twap, deposit, withdraw, approval, each with corresponding type declarations.
Client Package Dependencies
apps/agentic-chat/package.json
Added idb-keyval (^6.2.2) dependency for IndexedDB storage abstraction.
Client Transaction Utils
apps/agentic-chat/src/lib/transactionUtils.ts
Updated getSwapTokens to recognize swap-like types (swap, limitOrder, stopLoss, twap) via new SWAP_LIKE_TYPES constant instead of only accepting swap type.
Client Persistence Layer
apps/agentic-chat/src/stores/chatStore.ts
Introduced KnownTransaction interface and idb-keyval-backed storage adapter; extended ChatState with getKnownTransactions method; bumped STORE_VERSION to 4; implemented logic to derive known transactions from persisted tool results across all transaction types.
Client Chat Context
apps/agentic-chat/src/providers/ChatProvider.tsx
Integrated known transactions retrieval from chat store into AI server transport payload as knownTransactions field.
Client Transaction History UI
apps/agentic-chat/src/components/tools/GetTransactionHistoryUI.tsx
Added new icon imports; introduced TRANSACTION_LABELS mapping and composite type checks (isSwapLike, isSendLike, isReceiveLike, isContractLike); refactored conditional rendering logic to use type checks instead of direct tx.type comparisons; enhanced detail rendering for various transaction types.
Server Transaction Enrichment
apps/agentic-server/src/lib/transactionHistory/enrichment.ts
Introduced enrichTransactions function that maps known transactions to parsed transactions by txHash, updates transaction type and constructs tokenTransfers for swap-like types via buildSwapTokenTransfers helper.
Server Enrichment Tests
apps/agentic-server/src/lib/transactionHistory/__tests__/enrichment.test.ts
Comprehensive test suite covering reclassification of contract transactions to known types, handling partial swap info, case-insensitive matching, and enrichment for all new transaction types.
Server EVM Parser
apps/agentic-server/src/lib/transactionHistory/evmParser.ts
Added support for internal native ETH transfers via sumInternalNativeTransfers; enhanced transaction type detection and swap classification to consider internal transfers; updated tokenTransfers composition to include internal native transfer entries with dynamic native symbol resolution.
Server EVM Parser Tests
apps/agentic-server/src/lib/transactionHistory/__tests__/evmParser.test.ts
Added test suite for internal transactions classification covering token vs native ETH transfers and double-counting prevention.
Server Query Sorting
apps/agentic-server/src/lib/transactionHistory/query/sort.ts
Made SortOptions fields optional with defaults: field defaults to 'timestamp', order defaults to 'desc'; reworked defaulting logic to apply defaults when sortBy is not provided.
Server Query Tests
apps/agentic-server/src/lib/transactionHistory/__tests__/query.test.ts
Updated default sort behavior expectation to verify descending timestamp sort instead of returning original array order.
Server Schemas
apps/agentic-server/src/lib/transactionHistory/schemas.ts
Added optional internalTxs field to EvmTx schema; adjusted transactionHistoryToolInput schema fields (sortBy, offset, includeTransactions, renderTransactions) from required with defaults to optional; updated field descriptions.
Server Chat Routes
apps/agentic-server/src/routes/chat.ts
Extended buildWalletContext and WalletContext to include knownTransactions parameter; added knownTransactions to chatRequestSchema; updated handleChatRequest to destructure and propagate knownTransactions; lowered model temperature from 0.6 to 0.3.
Server Wallet Context
apps/agentic-server/src/utils/walletContextSimple.ts
Added KnownTransaction type export; extended WalletContext with knownTransactions field; enhanced getSafeAddressForChain to use predictSafeAddress when no known address exists and ownerAddress is present.
Server Transaction History Tool
apps/agentic-server/src/tools/transactionHistory.ts
Integrated enrichTransactions call with known transactions from wallet context; implemented dynamic limit calculation based on includeTransactions flag; updated tool description to provide prescriptive guidance on type usage and result expectations.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Client as agentic-chat<br/>(Client)
    participant Storage as IndexedDB<br/>(idb-keyval)
    participant Server as agentic-server<br/>(Routes & Tools)
    participant Parser as EVM Parser &<br/>Enrichment
    participant AIModel as AI Model

    User->>Client: Perform transaction (swap, send, etc.)
    Client->>Storage: Persist known transaction metadata via ChatStore
    
    User->>Client: Request transaction history
    Client->>Storage: Retrieve known transactions
    Storage-->>Client: Return KnownTransaction[]
    
    Client->>AIModel: Send chat request with knownTransactions
    AIModel->>Server: Forward request via buildWalletContext
    Server->>Server: Parse request schema with knownTransactions
    
    Server->>Parser: Call transactionHistoryTool with wallet context
    Parser->>Parser: enrichTransactions(allTxs, knownTransactions)
    
    Note over Parser: Map known transactions by txHash<br/>Reclassify contract → swap/send/etc.<br/>Build tokenTransfers for swap-like types
    
    Parser->>Parser: Enhance with internal native transfers
    Parser->>Parser: Apply filtering, sorting, pagination
    
    Parser-->>Server: Return enriched transactions
    Server-->>Client: Return transaction results
    Client->>Client: Render via GetTransactionHistoryUI with new types
    Client-->>User: Display enriched transaction history
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • feat: add tx history tool #101: Directly related modifications to transaction history feature spanning parsers, schemas, tools, UI components, and type exports across client and server applications.

Poem

🐰 Hopping through transactions, enriching with care,
Known swaps and sends now flow everywhere,
IndexedDB stores what the bunny remembers,
Internal transfers gleam like blockchain embers,
Type-safe and persistent, this history's rare! 📦✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/tx-history-enrichment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting to assertive to make CodeRabbit's nitpick more issues in your PRs.

@premiumjibles premiumjibles changed the title feat: enrich transaction history with known swap/send data feat: enrich transaction history with known transaction data Mar 15, 2026
premiumjibles and others added 2 commits March 17, 2026 14:45
Swaps are misclassified as "contract interactions" when Unchained returns
incomplete tokenTransfers data. Fix by sending a lightweight known
transactions map from the client (built from persistedTransactions) and
enriching misclassified contract txs before filtering.

Also parse internalTxs from Unchained to classify swaps where native ETH
is transferred via internal calls rather than top-level tx.value.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Remove .default() from schema fields that caused LLMs to echo unnecessary
parameters. Rewrite types description as positive directive with mapping.
Simplify renderTransactions to number-only type. Cap default context at
25 transactions. Move examples from system prompt into tool description.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add 6 new transaction types (limitOrder, stopLoss, twap, deposit, withdraw, approval)
and extract knownTransactions logic from ChatProvider into a chatStore selector that
covers all 9 tool types including approval/deposit sub-transactions.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@premiumjibles premiumjibles force-pushed the feat/tx-history-enrichment branch from 6cd1f6c to fb57255 Compare March 17, 2026 08:25
@premiumjibles premiumjibles marked this pull request as ready for review March 17, 2026 08:28
@premiumjibles premiumjibles merged commit 012946c into main Mar 17, 2026
3 of 4 checks passed
@premiumjibles premiumjibles deleted the feat/tx-history-enrichment branch March 17, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant